package com.bot.nft.module.op.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.auth.core.pojo.SaBaseClientLoginUser;
import com.bot.auth.core.util.StpClientLoginUserUtil;
import com.bot.auth.core.util.StpClientUtil;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.core.config.LoginStorage;
import com.bot.nft.core.enums.op.OpRofoEnum;
import com.bot.nft.module.mb.domain.vo.MbUserInfoVo;
import com.bot.nft.module.op.controller.OpRofoListController;
import com.bot.nft.module.op.domain.bo.OpRofoQueryBo;
import com.bot.nft.module.op.domain.vo.OpRofoListVo;
import com.bot.nft.module.op.domain.vo.OpRofoOpListVo;
import com.bot.nft.module.op.service.IRofoOpService;
import net.jodah.expiringmap.ExpiringMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.bot.common.util.CommonCryptogramUtil.doSm4CbcEncrypt;

/**
 * 描述:
 * 时间: 2023-12-03 17:44
 * 负责人: 王速
 **/
@RestController
@RequestMapping("/app/rofo")
@CrossOrigin
public class AppRofoListController extends OpRofoListController {


    @Resource
    private IRofoOpService iRofoOpService;

    /**
     * 查询优先购资格列表（app端）
     */
    @PostMapping("/{pageNo}/{pageSize}/queryMembership.do")
    public CommonResult<Page<OpRofoOpListVo>> queryMembership(@RequestBody OpRofoQueryBo rofoQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        Page<OpRofoOpListVo> rofoOpListVoPageInfo = iRofoOpService.queryAppRofoPage(rofoQueryBo, pageNo, pageSize);
        return CommonResult.data(rofoOpListVoPageInfo);

    }


    /**
     * 查询优先购资格（app端）
     */
    @PostMapping("/{pageNo}/{pageSize}/queryMember.do")
    public CommonResult<Page<OpRofoListVo>> queryMember(@RequestBody OpRofoQueryBo rofoQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String phone = doSm4CbcEncrypt(clientLoginUser.getPhone());
        rofoQueryBo.setPhone(phone);
        Page<OpRofoListVo> rofoListVoPageInfo = iRofoOpService.queryRofoList(rofoQueryBo, pageNo, pageSize);
        return CommonResult.data(rofoListVoPageInfo);
    }

    /**
     * 判断会员购买资格（app详情页）
     *
     * @param nftId
     * @return
     */
    @GetMapping("/{nftId}/assessment.do")
    public CommonResult<Boolean> assessment(@PathVariable("nftId") String nftId) {
        //获取当前登录用户
        SaBaseClientLoginUser clientLoginUser = StpClientLoginUserUtil.getClientLoginUser();
        String phoneMb = clientLoginUser.getPhone();
        //解密
        String phone = doSm4CbcEncrypt(phoneMb);
        Boolean signal = iRofoOpService.assessment(nftId, phone);
        if (!signal) {
            return CommonResult.ok(OpRofoEnum.FAIL.getName());
        }
        return CommonResult.ok(OpRofoEnum.SUCCESS.getName());
    }


}
